glglyphcache: Fix dropping caches unnecessarily
authorTimm Bäder <mail@baedert.org>
Sun, 10 Feb 2019 09:07:24 +0000 (10:07 +0100)
committerTimm Bäder <mail@baedert.org>
Sun, 10 Feb 2019 09:31:27 +0000 (10:31 +0100)
The first set of glyphs is created with a timestamp of 1. Later we
subtract the glyph timestamp from the cache timestamp, meaning we end up
with numbers ending in 9, e.g. 59. Now unfortunately !(60 <= 59), so we
do not end up incrasing the old_pixels count of the cache. Later we then
call lookup() and DEcrease the old_pixels count, which makes the
unsigned int wrap and cause a huge old_pixels value, which causes us to
drop the cache.

gsk/gl/gskglglyphcache.c

index 655da906ab7cb19e5de435b3f0ea4a5824fb4240..44618a257c2c549fdf009589dac820043c251e9e 100644 (file)
@@ -288,7 +288,9 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache *cache,
 
   if (value)
     {
-      if (cache->timestamp - value->timestamp >= MAX_AGE)
+      const guint age = cache->timestamp - value->timestamp;
+
+      if (MAX_AGE <= age && age < MAX_AGE + CHECK_INTERVAL)
         {
           GskGLGlyphAtlas *atlas = value->atlas;
 
@@ -363,16 +365,15 @@ gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self)
   self->timestamp++;
 
 
-  if (self->timestamp % CHECK_INTERVAL != 0)
+  if ((self->timestamp - 1) % CHECK_INTERVAL != 0)
     return;
 
   /* look for glyphs that have grown old since last time */
   g_hash_table_iter_init (&iter, self->hash_table);
   while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&value))
     {
-      guint age;
+      const guint age = self->timestamp - value->timestamp;
 
-      age = self->timestamp - value->timestamp;
       if (MAX_AGE <= age && age < MAX_AGE + CHECK_INTERVAL)
         {
           GskGLGlyphAtlas *atlas = value->atlas;